from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey, Enum, Text
from sqlalchemy.orm import relationship
from app.db.database import Base
import enum
from datetime import datetime

class Campus(enum.Enum):
    NEW = "NEW"
    OLD = "OLD"

class PostType(enum.Enum):
    SCIENCE = "SCIENCE"
    LIFE = "LIFE"
    OTHER = "OTHER"

class Activity(Base):
    __tablename__ = "activities"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), index=True)
    activity_time = Column(DateTime)
    submission_deadline = Column(DateTime)
    campus = Column(JSON)  # 存储校区列表
    type = Column(Enum(PostType))
    poster = Column(String(200))
    content = Column(Text)
    count_limit = Column(Integer, default=0)
    current_count = Column(Integer, default=0)
    
    publisher_id = Column(Integer, ForeignKey("users.id"))
    publisher = relationship("User", back_populates="activities")
    form = relationship("Form", back_populates="activity", uselist=False)

class Announcement(Base):
    __tablename__ = "announcements"
    
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(100), index=True)
    published_time = Column(DateTime, default=datetime.utcnow)
    campus = Column(JSON)  # 存储校区列表
    type = Column(Enum(PostType))
    poster = Column(String(200))
    content = Column(Text)
    
    publisher_id = Column(Integer, ForeignKey("users.id"))
    publisher = relationship("User", back_populates="announcements") 